<?php
require_once '../services/VehicleService.php';

class FetchInfo
{
	
	public $vehicleVO;
	
	public function getVehicleByVehicleID($vehicle_key)
	{
		$_instance = new VehicleService();
		$vehicleVO = $_instance->getVehicleByVehicleID($vehicle_key);
		return $vehicleVO;
	}
	public function createMessageBox($messages)
	{
		
		$message = new MessageVO();
		foreach ($messages->source as $message)
		{
			if($message->offer == 0)
			{
				$offervalue = '';
			}else{
				$offervalue = $message->offer;
			}
			echo "<div class='commentBox'>";
			echo "<div class='floatLeft'><p>Updated by <strong>".$message->messageOwener."</strong> on <span class='date'>".$message->dateTime."</span></p><p class='otherInfo'>".$message->message."</p></div>";
			echo "<div class='floatRight'><p class='bidAmount'>".$offervalue."</p></div>";
			echo "<div class='clearBoth'></div>";
			echo "</div>";
		}
	}
	
	public function createImageThump($images)
	{
		
		$image = new ImageVO();
		foreach ($images->source as $image)
		{
			
			echo "<img src='".$image->thumpUrl."'>";
		}
	}
	
	public function createReceipt($id)
	{
		$vehicleVO = new VehicleVO();

	$this->vehicleVO = self::getVehicleByVehicleID($id);

	$xml = simplexml_load_file("assets/data/receipt.xml");

	echo '<div class="recieptHeader"><div class="receiptLogo"></div>
		<div class="receiptHeaderText">Vehicle Bid Receipt</div>
		<div class="receiptHeaderRight">Bid# '.$this->vehicleVO->vehicle_id.'</div></div></div></div>
		<div class="boxBodyBlackReceipt">';
	foreach($xml->children() as $child)
  	{
		$attrArray = array();
		
		foreach($child->attributes() as $a => $b) 
  		{ 
			$attrArray[$a] = $b;
		}
		if($attrArray['visible'] == 'true')
		{
			echo '<div class="boxLblueReceipt floatLeft" style="width:100%;">
			<div class="boxLblueTlRecept"><div class="boxLblueTrRecept">
			<h2>'.$attrArray['label'].'</h2>
			</div></div>
			<div class="boxBodyLblueRecept">';
			foreach($child as $child_2)
			{
				$valueArray = array();
				foreach($child_2->attributes() as $a => $b) 
				{
					$valueArray[$a] = $b;
				}
				if($valueArray['visible'] == 'true')
				{
					$fieldValue = self::getVehicleValue($valueArray['id']);
				echo '<div class="fieldBox"><div class="fieldLabel">'.$valueArray['label'].'</div>
						<div class="fieldValue">'.$fieldValue.'</div></div>';
				}
									
			}
			echo '<div class="clearBoth"></div>
			</div>
			
			</div>';
		} 
}
	
	}
	
	private function getVehicleValue($id)
	{
		$value = '';
		switch($id)
		{
			case 1:
				$value = $this->vehicleVO->year;
				break;
				
			case 2:
				$value = $this->vehicleVO->make;
				break;
				
			case 3:
				$value = $this->vehicleVO->model;
				break;
					
			case 4:
				$value = $this->vehicleVO->color;
				break;
					
			case 5:
				$value = $this->vehicleVO->mileage;
				break;
					
			case 6:
				$value = $this->vehicleVO->vin;
				break;
					
			case 7:
				$value = $this->vehicleVO->drivetrain_type;
				break;
					
			case 8:
				$value = $this->vehicleVO->located_at;
				break;
					
			case 9:
				$value = $this->vehicleVO->v_street_address;
				break;
					
			case 10:
				$value = $this->vehicleVO->v_city;
				break;
					
			case 11:
				$value = $this->vehicleVO->v_state;
				break;
					
			case 12:
				$value = $this->vehicleVO->v_zip;
				break;
					
			case 13:
				$value = $this->vehicleVO->first_name;
				break;
					
			case 14:
				$value = $this->vehicleVO->street_address;
				break;
					
			case 15:
				$value = $this->vehicleVO->city;
				break;
					
			case 16:
				$value = $this->vehicleVO->state;
				break;
					
			case 17:
				$value = $this->vehicleVO->zip;
				break;
					
			case 18:
				$value = $this->vehicleVO->email;
				break;
					
			case 19:
				$value = $this->vehicleVO->phone;
				break;
					
			case 20:
				$value = $this->vehicleVO->asking_price;
				break;
					
			case 21:
				$value = $this->vehicleVO->bid_price;
				break;
							
			case 22:
				$value = $this->vehicleVO->accepted_price;
				break;
			
			case 23:
				$value = $this->vehicleVO->status;
				break;
			
			case 24:
				$value = $this->vehicleVO->removal_date;
				break;
				
			case 25:
				$value = $this->vehicleVO->delivery;
				break;
				
			case 26:
				$value = $this->vehicleVO->i_want_to;
				break;
				
			case 27:
				$value = $this->vehicleVO->delivery_option;
				break;
				
			case 28:
				$value = $this->vehicleVO->contact_me;
				break;
				
					

		}
		return $value;
	}
}
?>